home *** CD-ROM | disk | FTP | other *** search
- /* Copyright, 1990, Regents of the University of Colorado */
- #include <stdio.h>
- #include "shell.h"
-
- #define MAX_ENV 50
-
- #define HEAD "/*$DINO"
- #define FILES "/*$DINO FILES"
- #define NOFILES "/*$DINO NOFILES"
- #define SETFILES "/*$DINO SET FILES"
- #define RESET "/*$DINO RESET FILES"
- #define ONEFILE "/*$DINO FILE"
- #define ALL "/*$DINO ALL FILES"
-
- #define IS_CHAR(c) ((('a' <= c) && (c <= 'z')) || (('A' <= c) && (c <= 'Z')))
- #define IS_CHAR_NUM(c) (IS_CHAR(c) || (('0' <= c) && (c <= '9')))
-
- struct{
- char name[MAX_STRING];
- int len;
- FILE *fd;
- int all;
- int current;}
- table[MAX_ENV];
- int next_table = 0;
-
- char suffix[MAX_STRING] = {'D','\0'};
- char root[MAX_STRING];
-
- static BOOL model = FALSE;
-
- init(argc, argv)
- int argc;
- char *argv[];
- {
- int in;
-
- if (strcmp(argv[1], "new") == 0)
- model = TRUE;
- (void) strcpy(root, argv[2]);
-
- for (in = 3; in < argc; in++)
- if (argv[in][0] == '-')
- switch(argv[in][1])
- {
- case 's' :
- if (strlen(argv[in]) >2)
- strcpy(suffix, argv[in] +2);
- else strcpy(suffix,"");
- break;
- default : ;
- };
- }
- char *get_name(pt)
- char **pt;
- {
- static char name[MAX_STRING];
- char *nm = name;
- int i;
- char *p = *pt;
- register char c = *p;
-
- name[0] = '\0';
- c = *p;
- if (!IS_CHAR(c))
- while (c = *(++p), !IS_CHAR(c) && (c!='\n'));
- if (c=='\n') return name;
- do
- *(nm++) = c;
- while (c = *(++p), IS_CHAR_NUM(c) && (c!='\n'));
- *nm = '\0';
- *pt = p;
- return name;
- }
-
- load_table(pt)
- char *pt;
- {
- char *nm;
- do {
- nm = get_name(&pt);
- if (*nm != '\0'){
- char file[MAX_STRING];
-
- strcpy(table[next_table].name, nm);
- table[next_table].len = strlen(nm);
- if (model)
- (void) sprintf(file, "%s.%s.%s.c", root, suffix, nm);
- else
- (void) sprintf(file, "%s%s.c", nm, suffix);
- table[next_table].fd = fopen(file, "w");
- if (table[next_table].fd == NULL)
- {
- perror("\tShell");
- (void) fprintf(stderr,
- "\t\tUnable to open %s for writing.\n", file);
-
- exit(1);
- }
- table[next_table].current = table[next_table].all = 1;
- next_table++;
- if (next_table >= MAX_ENV)
- fprintf(stderr,"file splitter: too many environment structures");
- }
- } while (*nm != '\0');
- }
-
- set_files(pt)
- char *pt;
- {
- int tbl;
- int not_fnd;
- char *nm;
-
- for (tbl=0; tbl<next_table; tbl++)
- table[tbl].all = table[tbl].current = 0;
- do {
- nm = get_name(&pt);
- if (*nm != '\0'){
- tbl=0;
- not_fnd = 1;
- while ((tbl<next_table) && (not_fnd)) {
- if (table[tbl].len != strlen(nm))
- not_fnd = 1;
- else not_fnd =
- (0 != strncmp(nm, table[tbl].name, table[tbl].len));
- tbl++;
- }
- tbl--;
- if (not_fnd == 0)
- table[tbl].all = table[tbl].current = 1;
- }
- } while (*nm != '\0');
- }
-
- current_file(pt)
- char *pt;
- {
- int tbl;
- int not_fnd;
- char *nm;
-
- for (tbl=0; tbl<next_table; tbl++)
- table[tbl].current = 0;
- nm = get_name(&pt);
- if (*nm != '\0'){
- tbl=0;
- not_fnd = 1;
- while ((tbl<next_table) && (not_fnd)){
- if (table[tbl].len != strlen(nm))
- not_fnd = 1;
- else not_fnd =
- (0 != strncmp(nm, table[tbl].name, table[tbl].len));
- tbl++;
- }
- tbl--;
- if (not_fnd == 0)
- table[tbl].current = 1;
- }
- }
-
- split(pt)
- char *pt;
- {
- int tbl;
-
- if (strncmp(HEAD,pt,7) == 0)
- {
- if (strncmp(FILES,pt,strlen(FILES)) == 0)
- load_table(pt + strlen(FILES));
- else if (strncmp(NOFILES,pt,strlen(NOFILES)) == 0)
- exit(0);
- else if (strncmp(SETFILES,pt,strlen(SETFILES)) == 0)
- set_files(pt + strlen(SETFILES));
- else if (strncmp(RESET,pt,strlen(RESET)) == 0)
- for (tbl = 0; tbl < next_table; tbl++)
- table[tbl].all = table[tbl].current = 1;
- else if (strncmp(ONEFILE,pt,strlen(ONEFILE)) == 0)
- current_file(pt + strlen(ONEFILE));
- else if (strncmp(ALL,pt,strlen(ALL)) == 0)
- for (tbl = 0; tbl < next_table; tbl++)
- table[tbl].current = table[tbl].all;
- }
- else
- for(tbl = 0; tbl < next_table; tbl++)
- if(table[tbl].current){
- fprintf(table[tbl].fd, "%s", pt);
- /*printf("%s: %s",table[tbl].name, pt);*/}
- }
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int done = 0;
- char *line;
-
- init(argc,argv);
- while(!done){
- line = get_line(0);
- if (*line != '\0')
- split(line);
- else done = 1;
- }
- return(0);
- }
-